﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Text;
using System.Data.SqlClient;
using System.Collections.ObjectModel;
using MvcApplication6.DAL.Helper;
using MvcApplication6.Models;


namespace MvcApplication6.DAL
{
    public class UserDAL
    {
        //---------------------Menu_l1Select-----------------------------
        public List<UserModel> UserSearchByUser(string name, string password)
        {

            List<UserModel> lst = new List<UserModel>();

            UserModel obj = null;
            Collection<SqlParameter> parameterList = new Collection<SqlParameter>();
            parameterList.Add(new SqlParameter("@name", name));
            parameterList.Add(new SqlParameter("@password", password));

            SqlDataReader dr = SQLHelper.ExecuteReader("spUserSearchByUser", parameterList);

            while (dr.Read())
            {
                obj = new UserModel();

                obj.UserId = int.Parse(dr["id"].ToString());
                obj.name = dr["name"].ToString();
                obj.password = dr["password"].ToString();

                lst.Add(obj);
            }
            dr.Close();
            return lst;
        }

        //---------------------UserUpdate-----------------------------
        public int UserUpdate(int id, string name, string password)
        {
            Collection<SqlParameter> parameterList = new Collection<SqlParameter>();

            parameterList.Add(new SqlParameter("@id", id));
            parameterList.Add(new SqlParameter("@name", name));
            parameterList.Add(new SqlParameter("@password", password));

            int i = SQLHelper.ExecuteNonQuery("spUserUpdate", parameterList);

            return i;
        }
    }
}